# Author    : CoffeeChicken
# Date      : 2020-11-21 19:35
# Function  : 演示 处理json

import json
import requests
import os

headers = {
    # 'User-Agent': 'Mozilla/5.0 (Linux; Android 5.0; SM-G900P Build/LRX21T) AppleWebKit/537.36 (KHTML, like Gecko)'
    #               ' Chrome/66.0.3329.0 Mobile Safari/537.36',
    'User-Agent': 'Mozilla/5.0 (iPhone; U; CPU iPhone OS 4_3_3 like Mac OS X; en-us) AppleWebKit/533.17.9 '
                  '(KHTML, like Gecko) Version/5.0.2 Mobile/8J2 Safari/6533.18.5'
}

with open("video.json", "r") as f:
    dict1 = json.load(f)
    for item in dict1["aweme_list"]:
        nickname = item["author"]["nickname"]
        title = item['desc']
        video_url = item["video"]["play_addr"]["url_list"][0]
        est = requests.get(url=video_url, headers=headers)
        if not os.path.exists(nickname):
            os.mkdir(nickname)
        with open(f'{nickname}/{title}.mp4', 'wb') as f:
            f.write(est.content)
